/* The basicAoeAttack is an ability that instantly damages all viable targets in range of the user
 *
 * Author : Reinier
 */
class BasicAoeAttack extends Ability {

public var casterEffect : GameObject; /* The effect that will be displayed on the user of the ability */
public var targetEffect : GameObject; /* The effect that will be displayed on all targets */

/* The update function needs to call the parent's update function, since this is not done standardly in Unity */
function Update () {
	super.Update();
}

/* The Use function provides the actual functionality for the ability and returns a boolean whether is has actually
 * been used or a false value if the ability was still on cooldown
 * The aoe attack picks every single target and damages them according to the damage value of the ability and
 * the attack stat, if the user has one
 * It also displays an effect on both the user and every target, this will usually be a particle emitter that destroys itself
 */
function Use() : boolean {
	/* The currently counting cooldown will be checked, if the ability is still on cooldown, the function will do nothing and return a false value */
	if(currentCooldown <= 0) {
		/* All viable targets are picked with the GetHits function from the parent class Ability */
		var viableTargets : Collider[] = GetHits();
	
		/* Since this ability is meant as an 'area of effect' ability, every single viable target will be hit */
		for(i = 0; i < viableTargets.length; i++) {
			var charStats : CharacterStats;
			charStats = viableTargets[i].gameObject.GetComponent(CharacterStats);
			if(charStats){
				/* The damage is modified if an attack stat is present on the user */
				var damageAmount : int;
				damageAmount = ApplyAttackModifier();
				charStats.OnDamage(damageAmount, gameObject);
				
				/* An effect is displayed on the target, the effect is responsible for its own destruction */
				if(targetEffect) {
					var tempTargetEffect : GameObject = Instantiate(targetEffect, viableTargets[i].gameObject.transform.localPosition, viableTargets[i].gameObject.transform.localRotation);
					/* The effect's transform is parented to the targets transform so it follows it around */
					tempTargetEffect.transform.parent = viableTargets[i].gameObject.transform;
				}
			}
		}
		
		/* An effect is displayed on the user if one is set */
		if(casterEffect){
			var tempCasterEffect : GameObject = Instantiate(casterEffect, gameObject.transform.localPosition, gameObject.transform.localRotation);
			/* The effect's transform is parented to the targets transform so it follows it around */
			tempCasterEffect.transform.parent = gameObject.transform;
		}
		
		/* If the ability has been used correctly it will return true */
		return true;
	}
	else{
		return false;
	}
}

}